basket.require({
	url : 'http://cdn.bootcss.com/jquery/2.1.4/jquery.min.js'
}, {
	url : "http://cdn.bootcss.com/angular.js/1.4.3/angular.min.js"
}, {
	url : settings.getIp() + "/peiwan-server/static/js/persistence.js"
}, {
	url : settings.getIp() + "/peiwan-server/static/js/timer.js"
}).then(ready);

function ready() {
	persistence.setNamespace("peiwan_admin");
	function ajax(url, data, callback) {
		$.ajax({
			url : settings.getBaseUrl() + url,
			data : data,
			async : false,
			success : callback
		});
	}
	var peiwanAdmin = angular.module('peiwan_admin', []);
	peiwanAdmin.controller('LoginCtrl', [ "$scope", function(s) {
		if (persistence.get("session")) {
			location.href = "admin_main.html";
		}
		s.login = function(username, pwd) {
			ajax("/login", {
				username : username,
				password : pwd
			}, function(data) {
				var json = JSON.parse(data);
				if (json.status == 1) {
					alert("帐号密码错误");
					return;
				}
				persistence.put("session", json.entity.session);
				location.href = "admin_main.html";
			});
		}
	} ]);
}
